package com.example.client.api.unit;

import com.example.server.service.Productionservice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;

@Controller

@RequestMapping("/production")
@CrossOrigin
@Slf4j

public class ProductionController {
    @Resource
    private Productionservice productionservice;
    @CrossOrigin
    @GetMapping("/getinterstway")
    @ResponseBody
    public HashMap<String,Object> identify(String user_name, String user_identity){
        HashMap<String,Object> result = new HashMap<>();
        result.put("result",productionservice.getInterstway());
        return result;
    }
    @CrossOrigin
    @GetMapping("/createproduction")
    @ResponseBody
    public HashMap<String,Object> createproduction(String p_id, String p_name, String p_createid, String p_info, Integer minyear, Integer maxyear, Integer limitmoney, String interstway){
        HashMap<String,Object> result = new HashMap<>();
        log.info("新建服务产品,id="+p_id+"name="+p_name+",createid="+p_createid+",info="+p_info+",minyear="+minyear
                +",maxyear="+maxyear+",limitmoney="+limitmoney+",interstway="+interstway);
        result.put("result",productionservice.createproduction(p_id, p_name,p_createid,p_info,minyear,maxyear,limitmoney,interstway));
        return result;
    }
    @CrossOrigin
    @GetMapping("/updateproduction")
    @ResponseBody
    public HashMap<String,Object> updateproduction(String p_id, String p_name, String p_createid, String p_info, Integer minyear, Integer maxyear, Integer limitmoney, String interstway){
        HashMap<String,Object> result = new HashMap<>();
        log.info("更新服务产品,id="+p_id+"name="+p_name+",createid="+p_createid+",info="+p_info+",minyear="+minyear
                +",maxyear="+maxyear+",limitmoney="+limitmoney+",interstway="+interstway);
        result.put("result",productionservice.updateproduction(p_id, p_name,p_createid,p_info,minyear,maxyear,limitmoney,interstway));
        return result;
    }
    @CrossOrigin
    @GetMapping("/getAllproduction")
    @ResponseBody
    public HashMap<String,Object> getAllproduction(){
        HashMap<String,Object> result = new HashMap<>();
        log.info("调用Getallproduction");
        result.put("result",productionservice.getAllproduction());
        return result;
    }
    @CrossOrigin
    @GetMapping("/setlocaltioninfo")
    @ResponseBody
    public HashMap<String,Object> setlocaltioninfo(String p_id,String localtioninfo){
        HashMap<String,Object> result = new HashMap<>();
        log.info("调用setlocaltioninfo");
        result.put("result",productionservice.setlocaltion(p_id,localtioninfo));
        return result;
    }
    @CrossOrigin
    @GetMapping("/deleteproduction")
    @ResponseBody
    public HashMap<String,Object> deleteproduction(String p_id){
        HashMap<String,Object> result = new HashMap<>();
        log.info("删除production:"+p_id);
        result.put("result",productionservice.deleteproduction(p_id));
        return result;
    }
    @CrossOrigin
    @GetMapping("/getlocaltion")
    @ResponseBody
    public HashMap<String,Object> getlocaltion(){
        HashMap<String,Object> result = new HashMap<>();
        log.info("调用getlocaltion");
        result.put("result",productionservice.getlocaltion());
        return result;
    }
    @CrossOrigin
    @GetMapping("/getprodunctionbyId")
    @ResponseBody
    public HashMap<String,Object> getprodunctionbyId(String p_id){
        HashMap<String,Object> result = new HashMap<>();
        log.info("getprodunctionbyId");
        result.put("result",productionservice.getprodunctionbyId(p_id));
        return result;
    }
    @CrossOrigin
    @GetMapping("/locklimit")
    @ResponseBody
    public HashMap<String,Object> locklimit(String p_id,int num){
        HashMap<String,Object> result = new HashMap<>();
        log.info("locklimit,p_id="+p_id+",num="+num);
        productionservice.locklimit(p_id,num);
        result.put("result","修改成功");
        return result;
    }
    @CrossOrigin
    @GetMapping("/releaselimit")
    @ResponseBody
    public HashMap<String,Object> releaselimit(String p_id,int num){
        HashMap<String,Object> result = new HashMap<>();
        log.info("releaselimit,p_id="+p_id+",num="+num);
        productionservice.releaselimit(p_id,num);
        result.put("result","修改成功");
        return result;
    }
    @CrossOrigin
    @GetMapping("/addlimit")
    @ResponseBody
    public HashMap<String,Object> addlimit(String p_id,int num){
        HashMap<String,Object> result = new HashMap<>();
        log.info("addlimit,p_id="+p_id+",num="+num);
        productionservice.addlimit(p_id,num);
        result.put("result","修改成功");
        return result;
    }
}
